<template>
  <div class="boxs">
    <!-- 面包屑组件 -->
    <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
      <el-breadcrumb-item>
        <!-- <img src="@/assets/userCenter/组132.png" alt="" /> -->
        <i class="el-icon-user-solid"></i>
        <span class="span" style="color: #666"> 用户中心</span>
      </el-breadcrumb-item>
      <el-breadcrumb-item>
        <span class="span" style="color: #666">我的认证</span>
      </el-breadcrumb-item>
    </el-breadcrumb>
    <div class="f1">
      <project-tab />
      <div class="title">我的认证</div>
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        label-width="180px"
      >
        <el-form-item label="" label-width="0px">
          <el-input
            v-model="queryParams.entname"
            placeholder="请输入企业名称/统一社会信用代码"
            @keyup.enter.native="handleQuery"
          >
            <div slot="suffix" class="search_input">
              <img
                @click="handleQuery()"
                src="@/assets/userCenter/组26.png"
                alt=""
              />
            </div>
          </el-input>
        </el-form-item>
        <el-form-item label="企业认证类型" prop="customsauthgrade">
          <el-select clearable v-model="type" placeholder="请选择企业认证类型">
            <el-option label="外贸企业" value="1"></el-option>
            <el-option label="物流服务商" value="2"></el-option>
            <el-option label="仓储服务商" value="3"></el-option>
            <el-option label="关务服务商" value="4"></el-option>
          </el-select>
        </el-form-item>
      </el-form>

      <!-- 表格 -->
      <div class="table" v-if="list">
        <el-table
          :data="list"
          border
          style="width: 100%"
          highlight-current-row
          stripe
          :header-cell-style="{
            background: '#F1F5FF',
            color: '#4D4D4D',
          }"
        >
          <el-table-column
            prop="id"
            label="订单号"
            width="180"
            align="center"
            fixed="left"
          >
          </el-table-column>
          <el-table-column
            prop="entname"
            label="企业名称"
            align="center"
            width="300"
          >
          </el-table-column>
          <el-table-column
            prop="creditno"
            label="统一社会信用代码"
            width="220"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop=""
            label="企业认证类型"
            width="160"
            align="center"
          >
            <template slot-scope="scope">
              <span>{{
                list[scope.$index].type == "1"
                  ? "外贸企业"
                  : list[scope.$index].type == "2"
                  ? "物流服务商"
                  : list[scope.$index].type == "3"
                  ? "仓储服务商"
                  : "关务服务商"
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="inputdate"
            label="申请时间"
            width="240"
            align="center"
          >
            <template slot-scope="scope">{{
              scope.row.inputdate | getDate
            }}</template>
          </el-table-column>
          <el-table-column prop="" label="有效期至" width="160" align="center">
            <template slot-scope="scope">
              {{
                list[scope.$index].authresult == "不通过" ||
                list[scope.$index].authresult == null
                  ? "-"
                  : list[scope.$index].validto
              }}
            </template>
          </el-table-column>
          <el-table-column prop="" label="认证结果" width="160" align="center">
            <template slot-scope="scope">
              <span>{{
                list[scope.$index].status == "0"
                  ? "认证中"
                  : list[scope.$index].status == "1"
                  ? list[scope.$index].authresult
                    ? list[scope.$index].authresult
                    : "审核中"
                  : list[scope.$index].status == "2"
                  ? "未提交"
                  : ""
              }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="address"
            label="操作"
            align="center"
            fixed="right"
            width="130"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="examine(scope.$index, list)"
                >查看</el-button
              >
              <el-button
                v-if="
                  list[scope.$index].authresult &&
                  list[scope.$index].authresult != '不通过'
                "
                size="mini"
                type="text"
                @click="download(scope.$index, list)"
                >下载</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 分页器 -->
      <div class="pagination" v-if="list">
        <el-pagination
          background
          layout="prev, pager, next"
          @next-click="nextClick()"
          @prev-click="prevClick()"
          @current-change="handlePageChange"
          :total="pages * 10"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { list, download } from "@/api/authentication/index.js";
import ProjectTab from "@/components/ProjectTab.vue";
export default {
  components: { ProjectTab },
  data() {
    return {
      queryParams: {
        entname: "",
      },
      type: "",
      businessid: "",
      pageNum: 1,
      pageSize: 10,
      pages: 1,
      list: null,
    };
  },
  watch: {
    type(old, end) {
      this.type = old;
      this.queryParams.pageNum = 1;
      this.findkjapply();
    },
  },
  // 过滤器
  filters: {
    getDate: function (value) {
      if (!value) return value;
      let date = value.split(" ")[0];
      return date;
    },
  },
  mounted() {
    document.documentElement.scrollTop = 0;
    this.businessid = localStorage.getItem("businessid");
    this.findkjapply();
  },
  methods: {
    // 下载
    download(index, data) {
      let entrzid = data[index].id;
      download(entrzid).then((res) => {
        let url = res.data.filepath;
        const a = document.createElement("a"); // 动态创建a标签，防止下载大文件时，用户没看到下载提示连续点击
        a.setAttribute("target", "_blank");
        a.download = "企业信用认证证书";
        a.href = url;
        a.click();
      });
    },
    // 获取信息
    async findkjapply() {
      let params = {
        businessid: this.businessid,
        type: this.type,
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        creditno: this.queryParams.entname,
      };
      list(params)
        .then((res) => {
          this.list = res.data.list;
          this.pages = res.data.pages;
        })
        .catch((err) => {});
    },
    // 查看
    examine(index, data) {
      let id = data[index].id;
      let type = data[index].type;
      if (data[index].status == "2") {
        sessionStorage.setItem("rzid", id);
        // window.open("", "_blank");
        this.$router.push("/flow1");
        return;
      }
      this.$router.push(`/userDetails?id=${id}&type=${type}`);
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.findkjapply();
    },
    //点击下一页
    nextClick() {
      this.pageNum += 1;
      this.findkjapply();
    },
    //点击上一页
    prevClick() {
      this.pageNum -= 1;
      this.findkjapply();
    },
    //点击数字改变page的值
    handlePageChange(currentPage) {
      this.pageNum = currentPage;
      this.findkjapply();
    },
  },
};
</script>

<style lang="scss" scoped>
.boxs {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  // 面包屑
  .breadcrumb {
    display: flex;
    align-items: center;
    height: 40px;
    font-size: 16px;
    background-color: rgb(242, 244, 247);
    .icon {
      margin: 0 10px 0 4px;
    }
    .span {
      font-size: 16px;
      font-family: Source Han Sans SC;
      font-weight: 400;
      color: #999999;
    }
    img {
      width: 21px;
      height: 21px;
      margin-right: 5px;
    }
  }
  .f1 {
    box-sizing: border-box;
    padding: 20px 35px;
    .title {
      font-size: 18px;
      font-family: Source Han Sans SC;
      font-weight: 400;
      color: #000000;
      margin-bottom: 28px;
    }
    .search_input {
      cursor: pointer;
      height: 100%;
      position: relative;
      display: flex;
      align-items: center;
      img {
        width: 16px;
        position: absolute;
        right: 6px;
      }
    }
    // 表格

    .table {
      box-sizing: border-box;
      width: 850px;
      background-color: #fff;
      height: 100%;
      margin-bottom: 20px;
      cursor: pointer;
      overflow: auto;
      margin-top: 30px;
      .span {
        display: inline-block;
        // width: 0.1563px;
        // height: 0.125px;
        font-size: 15px;
        font-family: Source Han Sans SC;
        font-weight: 400;
        margin-right: 5px;
        color: #ccc;
        border-bottom: 1px solid #ccc;
        cursor: pointer;
        margin-right: 10px;
      }
      .span1 {
        display: inline-block;
        font-size: 15px;
        font-family: Source Han Sans SC;
        font-weight: 400;
        margin-right: 5px;
        color: #3f6ef2;
        border-bottom: 1px solid #3f6ef2;
        cursor: pointer;
      }
      .nactive {
        font-size: 14px;
        margin-right: 5px;
        color: #3f6ef2;
        border-bottom: 1px solid #3f6ef2;
      }
      .state-bar {
        span {
          font-size: 14px;
          font-family: Source Han Sans SC;
          font-weight: 400;
          color: #606266;
          margin-right: 10px;
        }
      }
    }
    // 分页器
    .pagination {
      display: flex;
      justify-content: right;
      span {
        font-size: 16px;
        font-family: Source Han Sans SC;
        font-weight: 400;
        color: #666666;
        margin-top: 1px;
      }
    }
  }
}
::v-deep .el-form {
  display: flex;
}
// 表格滚动条
::v-deep .el-table {
  th.el-table__cell > .cell {
    font-size: 16px;
    font-weight: 400;
  }
  .cell {
    font-size: 16px;
  }
  .el-table__body-wrapper {
    overflow: auto;
    height: calc(100% - 85px);

    &::-webkit-scrollbar {
      width: 0; /* 纵向滚动条 宽度 */
      height: 15px; /* 横向滚动条 高度 */
    }
    &::-webkit-scrollbar-thumb {
      width: 10px; /* 横向滚动条 宽度 */
      height: 15px; /* 纵向滚动条 高度 */
      background-color: rgb(167, 164, 164);
    }
  }
}
::v-deep .el-form-item--small .el-form-item__label {
  line-height: 37px;
}
/* 输入框样式  */
::v-deep .el-input__inner {
  box-sizing: border-box;
  font-size: 15px;
  border: 1px solid #e0e0e0;
  border-radius: 0px;
  padding: 10px;
  color: #606266;
  outline: 0;
  line-height: 35px !important;
  width: 300px;
  height: 37px;
  background: #ffffff;
  border-radius: 4px;
}
::v-deep .el-table th.el-table__cell > .cell {
  text-align: center;
}
// 表格样式
::v-deep .el-table th.el-table__cell > .cell {
  font-size: 16px;
}
::v-deep.el-pagination {
  display: flex;
  justify-content: flex-end;
  margin-top: 15px;
  font-size: 16px;
  font-family: Source Han Sans SC;
  font-weight: 400;
  color: #666666;
}
/* 表格 */
::v-deep .el-table {
  th.el-table__cell > .cell {
    font-size: 15px;
    font-weight: 400;
  }
  .cell {
    font-size: 15px;
  }
}
::v-deep .el-form-item__label {
  font-size: 14px;
}
</style>
<style lang="scss">
/* 分页器 */
.el-pagination.is-background .el-pager li {
  border-radius: 20px;
}
.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #3f6ef2;
}

.el-pagination.is-background .btn-next,
.el-pagination.is-background .btn-prev,
.el-pagination.is-background .el-pager li {
  background-color: transparent;
}
/* 表格 */
.el-table {
  th.el-table__cell > .cell {
    font-size: 14px;
    font-weight: 400;
  }
  .cell {
    font-size: 14px;
  }
}
.el-table tr {
  height: 40px;
}
.el-table .el-table thead {
  height: 40px;
}

.el-pagination.is-background .el-pager li:not(.disabled).active {
  background-color: #3f6ef2;
}
</style>
